package com.lovo.bbs.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.naming.NamingException;

import com.lovo.bbs.po.RankPo;
import com.lovo.bbs.util.DbUtil;
import com.lovo.bbs.util.MysqlDb;

public class RankDao {
	public RankDao(){
		
	}

	/**
	 * 取得所有等级Po列表
	 * @return
	 * @throws NamingException
	 * @throws SQLException
	 */
	public  ArrayList<RankPo> getAllRank() throws NamingException, SQLException {
		ArrayList<RankPo> pos = new ArrayList<RankPo>();
		
		MysqlDb mysqldb = new MysqlDb();
		mysqldb.setPool(true);
		Connection con = DbUtil.getConn(mysqldb);

		String sql = "select 	rankid, rankname, rankimg, usertitle from rank ";
		ResultSet rs = con.prepareStatement(sql).executeQuery();
		while(rs.next()){
			RankPo po = new RankPo();
			po.setRankid(rs.getInt(1));
			po.setRankname(rs.getString(2));
			po.setRankimg(rs.getString(3));
			po.setRanktitle(rs.getString(4));
			pos.add(po);
		}
		mysqldb.closeRS(rs);
		mysqldb.closeConnection(con);
		return pos;
	}

}
